Skip to content

Give programs an empty stdin by default, with -InheritStdin to opt out - #86

Merged
HalRiveria-Bot merged 2 commits into
mainfrom
fix/stdin-nul
Nov 30, 2026
Merged

HalRiveria-Bot merged 2 commits into
mainfrom
fix/stdin-nul

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

Programs the kit starts inherited PowerShell's own stdin. With the script's stdin piped or redirected in, a program that reads its input took input meant for the script; one that waits for input sat until its time limit, or forever without one.

  • Programs now get an empty stdin: NUL in the normal start, a pipe closed at once on the Process.Start fallback. One that reads it gets the end of input straight away.
  • -InheritStdin on Start-PkProcess, Invoke-PkProcessWithTimeout, Invoke-PkProcessBatch and Invoke-PkProcessDispatch passes PowerShell's own stdin on, as before. A command's or job's own InheritStdin key ($true/$false) overrides it either way, and a bad value is a failed start, as with MaxOutputChars. Scripts using that key name for something of their own need to rename it.
  • timeout.exe refuses to run without a console as its stdin, so cmd /c timeout /t 5 fails at once now. The README says so and suggests ping -n 6 127.0.0.1 >nul; -InheritStdin helps only if the script's own stdin is a console.
  • Known gap, in the README and a test: on the fallback path, on .NET Framework with a UTF-8 console, Process.Start itself writes a byte-order mark into the redirected stdin, so it isn't quite empty there.
  • The C# changed, so TypesVersion goes to 13.

Tested

New harness section BI starts a fresh PowerShell with a file as its stdin, on both start paths, and checks what set /p reads through each of the four functions and both per-command keys, plus timeout.exe and a UTF-8 console.

  • Before the change (5.1 and 7, both start paths): set /p read the script's lines ([line1] to [line4]) through all four functions; 29 of the section's assertions failed, counting the ones for the new parameter.
  • After: all pass.
  • Full harness: ALL PASSED (641 assertions, none skipped) on Windows PowerShell 5.1, then PowerShell 7, in fresh processes. Section AR still shows both start paths giving the same results.

🤖 Generated with Claude Code

HalRiveria and others added 2 commits November 30, 2026 14:14
Programs the kit starts inherited PowerShell's own stdin, so one that reads
its input could take input meant for the script, or wait for it until its
time limit. They now get NUL (on the Process.Start path, a closed pipe).
-InheritStdin, or a command's InheritStdin key, gives PowerShell's own back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HalRiveria-Bot
HalRiveria-Bot merged commit f12ca05 into main Nov 30, 2026
2 checks passed
@HalRiveria-Bot
HalRiveria-Bot deleted the fix/stdin-nul branch November 30, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants